package org.springblade.modules.admin.vo.plan;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.enums.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zcc
 * @version 1.0
 * @date 2021/12/23 16:16
 */
@Data
public class PlanResultVo {

	@ApiModelProperty("id")
	private Long id;

	@ApiModelProperty("任务编码")
	private String planNum;

	@ApiModelProperty("用户ids")
	private String userIds;

	@ApiModelProperty("计划执行人")
	private String userNames;

	@ApiModelProperty("实际执行人")
	private String realUserNames;


	@ApiModelProperty("组名称")
	private String groupName;

	@ApiModelProperty("项目名称")
	private String buildingName;

	@ApiModelProperty("梯号")
	private String elevatorAddress;

	@ApiModelProperty("工单类型编号")
	private Integer typeStatus;

	@ApiModelProperty("工单类型名称")
	private String typeStatusName;

	@ApiModelProperty("保养类型编号")
	private Integer planCheckType;

	@ApiModelProperty("保养类型名称")
	private String planCheckTypeName;

	@ApiModelProperty("排期时间")
	private String planDate;

	@ApiModelProperty("工单开始时间")
	private Date beginTime;

	@ApiModelProperty("工单完成时间")
	private Date endTime;

	@ApiModelProperty("工单创建时间")
	private Date createTime;

	@ApiModelProperty("状态编码")
	private Integer status;

	@ApiModelProperty("状态名称")
	private String statusName;

	@ApiModelProperty("报障渠道")
	private Integer planFrom;

	@ApiModelProperty("报障渠道描述")
	private String planFromName;

	@ApiModelProperty("报障人")
	private String faultName;

	@ApiModelProperty("图片数量")
	private Integer imageNum = 0;

	@ApiModelProperty("审核状态")
	private Integer approveStatus;

	@ApiModelProperty("审核状态描述")
	private String approveStatusName;

	@ApiModelProperty("状态编码集合--用于保养")
	private List<Integer> statusList;

	private String ownPlanId;

	private Integer ownPlanIds;

	@ApiModelProperty("执行人信息")
	private String userSignInfos;

	@ApiModelProperty("电梯实时停梯状态： 1-正常 2-停梯")
	private Integer isStop;

	@ApiModelProperty("停梯状态： 1-正常 2-停梯")
	private Integer elevatorIsStop;

	private Integer workMinute;

	private String faultReasonItem;


	private String problemItemName;

	@ApiModelProperty("计划完成时间")
	private String planFinishTime;

	/**
	 * 紧急程度
	 */
	private Integer emerProcType;

	/**
	 * 工单类型
	 */
	private Integer workOrderType;

	/**
	 * 紧急程度描述
	 */
	private String emerProcTypeName;

	/**
	 * 工单类型描述
	 */
	private String workOrderTypeName;

	/**
	 * 2024-04-24 新增来源字段
	 */
	private Integer sourcePlanType;

	/**
	 * 2024-04-24 新增来源字段描述
	 */
	private String sourcePlanTypeName;

	private Integer reportCount;

	@ApiModelProperty("电梯维修次数统计文案")
	private String wxNumberDescs;

	@ApiModelProperty(value = "评分状态 0-未评分，1-已评分,-1不符合评分的工单")
	private Integer scoreStatus;

	@ApiModelProperty(value = "评分类型1:有效订单，2：无效工单3：无法判断")
	private Integer scoreType;

	@ApiModelProperty(value = "是否申请技术支持: 0-否，1-是")
	private Integer applyTsFlag;

	@ApiModelProperty(value = "是否申请平台专家: 0-否，1-是")
	private Integer applyPeFlag;

	@ApiModelProperty(value = "是否增派: 0-否，1-是")
	private Integer addUserFlag;

	@ApiModelProperty(value = "是否转派: 0-否，1-是")
	private Integer transferUserFlag;

	@ApiModelProperty(value = "1:非年审，2:年审")
	private Integer auditType;

	@ApiModelProperty(value = "任务执行人总数")
	private Integer taskUserTotal;

	@ApiModelProperty(value = "维修原因1:部件损坏2:安装问题3:维保问题")
	private String malfunctionType;


	public void setEmerProcType(Integer emerProcType) {
		if(Func.isNotEmpty(emerProcType)){
			this.emerProcTypeName = EmerProcTypeEnum.getName(emerProcType);
		}
		this.emerProcType = emerProcType;
	}

	public void setWorkOrderType(Integer workOrderType) {
		if(Func.isNotEmpty(workOrderType)){
			this.workOrderTypeName = WorkOrderTypeEnum.getName(workOrderType);
		}
		this.workOrderType = workOrderType;
	}

	public void setUserSignInfos(String userSignInfos) {
		this.userSignInfos = userSignInfos;
		List<PlanUserSignDetailVo> list = new ArrayList<>();
		if (StrUtil.isNotEmpty(userSignInfos)) {
			String[] split = userSignInfos.split("%");
			for (String str : split) {
				PlanUserSignDetailVo planUserSignDetailVo = JSON.parseObject(str, PlanUserSignDetailVo.class);
				if (planUserSignDetailVo.getIsTakePartIn()) {
					list.add(planUserSignDetailVo);
				}
			}
		}
		if (list.size() > 0) {
			this.realUserNames = String.join(",", list.stream().map(PlanUserSignDetailVo::getUserName).collect(Collectors.toList()));
			this.taskUserTotal = list.size();
		}

	}


	public void setOwnPlanId(String ownPlanId) {
		this.ownPlanId = ownPlanId;
		if (StrUtil.isNotEmpty(ownPlanId)) {
			this.ownPlanIds = ownPlanId.split(",").length;
		} else {
			this.ownPlanIds = 0;
		}
	}

	public void setApproveStatus(Integer approveStatus) {
		this.approveStatus = approveStatus;
		this.approveStatusName = ApproveStatusEnum.getName(approveStatus);
	}

	public void setPlanFrom(Integer planFrom) {
		this.planFrom = planFrom;
		this.planFromName = PlanContentFormTypeEnum.getName(planFrom);
	}

	public void setTypeStatus(Integer typeStatus) {
		this.typeStatus = typeStatus;
		if (typeStatus == MaintainPlanContentEnum.MAINTAIN_BY.getId()) {
			this.typeStatusName = MaintainPlanContentEnum.MAINTAIN_BY.getName();
		} else if (typeStatus == MaintainPlanContentEnum.MAINTAIN_WX.getId()) {
			this.typeStatusName = MaintainPlanContentEnum.MAINTAIN_WX.getName();
		} else if (typeStatus == MaintainPlanContentEnum.MAINTAIN_KR.getId()) {
			this.typeStatusName = MaintainPlanContentEnum.MAINTAIN_KR.getName();
		}
	}

	public void setPlanCheckType(Integer planCheckType) {
		this.planCheckType = planCheckType;
		if (planCheckType != null) {
			if (planCheckType == PlanContentCheckTypeEnum.HALF_MONTH.getId()) {
				this.planCheckTypeName = PlanContentCheckTypeEnum.HALF_MONTH.getName();
			} else if (planCheckType == PlanContentCheckTypeEnum.QUARTER.getId()) {
				this.planCheckTypeName = PlanContentCheckTypeEnum.QUARTER.getName();
			} else if (planCheckType == PlanContentCheckTypeEnum.HALF_YEAR.getId()) {
				this.planCheckTypeName = PlanContentCheckTypeEnum.HALF_YEAR.getName();
			} else if (planCheckType == PlanContentCheckTypeEnum.YEAR.getId()) {
				this.planCheckTypeName = PlanContentCheckTypeEnum.YEAR.getName();
			} else if (planCheckType == PlanContentCheckTypeEnum.USER_DEFINED.getId()) {
				this.planCheckTypeName = PlanContentCheckTypeEnum.USER_DEFINED.getName();
			} else if (planCheckType == PlanContentCheckTypeEnum.SPECIAL.getId()) {
				this.planCheckTypeName = PlanContentCheckTypeEnum.SPECIAL.getName();
			}
		}
	}
}
